package com.ty.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ty.entity.Book;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author : txy
 * @create : 2024/1/9 13:39
 */
public interface BookMapper extends BaseMapper<Book> {
    @Select("select * from periodical_tb ${ew.customSqlSegment}")
    @Results({
            //因为type_id字段拿去关联外表，想要赋值给bookinfo还要再映射一次
            @Result(property = "type", column = "type"),
            @Result(property = "pt", column = "type",
                    one = @One(select = "com.ty.mapper.BookTypeMapper.selectByTypeId"))
    })
    Page<Book> selectAllBooks(Page<Book> page, @Param(Constants.WRAPPER) Wrapper<Book> wrapper);

    @Select("select * from periodical_tb where type = #{type} ")
    List<Book> selectBooksByTypeId(Integer type);

    @Select("select * from periodical_tb where id = #{id} ")
    Book selectBooksById(Integer id);

    //获取库存不足的书籍
    @Select("select name,num from periodical_tb where num<#{num}")
    List<HashMap<String, String>> selectBooks(Integer num);
}
